package com.tb.education.server;

import com.tb.education.common.SessionContext;
import org.rockyang.tio.common.starter.annotation.TioAioListener;
import org.rockyang.tio.core.starter.listener.SocketServerAioListener;
import org.tio.core.ChannelContext;
import org.tio.core.intf.Packet;

/**
 * @author wangze
 * @date 2020-07-08 15:00.
 **/
@TioAioListener
public class ServerAioListener  implements SocketServerAioListener {
	@Override
	public void onAfterConnected(ChannelContext channelContext, boolean isConnected, boolean isReconnect) throws Exception {
		SessionContext sessionContext=new SessionContext();
		channelContext.setAttribute(sessionContext);
	}

	@Override
	public void onAfterDecoded(ChannelContext channelContext, Packet packet, int packetSize) throws Exception {
		System.out.println("onAfterDecoded");
	}

	@Override
	public void onAfterReceivedBytes(ChannelContext channelContext, int receivedBytes) throws Exception {
		System.out.println("收到字符串个数:"+receivedBytes);
		System.out.println("onAfterReceivedBytes");
	}

	@Override
	public void onAfterSent(ChannelContext channelContext, Packet packet, boolean isSentSuccess) throws Exception {
		System.out.println("onAfterSent");
	}

	@Override
	public void onAfterHandled(ChannelContext channelContext, Packet packet, long cost) throws Exception {
		System.out.println("onAfterHandled");
	}

	@Override
	public void onBeforeClose(ChannelContext channelContext, Throwable throwable, String remark, boolean isRemove) throws Exception {
		System.out.println("onBeforeClose");
	}
}
